//
// Author    : Pablo Bosch
// Contact   : pboschvivancos@epo.org
// Last Modif: 10/04/2005
//

var MOD_WOI={
  law: "EPC",
  woitab:[]
};



MOD_WOI.ok_header=function(clist,opttext) {
  return stdcls_apply_grant("header",clist,MOD_WOI.law)+BR; //mutatismutandis(clist,"new.inv",opttext);
}


MOD_WOI.ok_claim=function(cl,pn,lang) {
 var woisa="";
 if(!isDocEmpty(pn) && !isDocpureB(pn)) {
   switch(lang) {
   case "EN":
     woisa+=comm_claim_is_novel(cl,pn,lang);
     woisa+="The problem to be solved by the present invention may therefore be ";
     woisa+="regarded as "+BR;
     woisa+="The solution to this problem proposed in claim "+cl+" of the present application is ";
     woisa+="considered as involving an inventive step (Article 33(3) PCT) for the following reasons:"+BR;
     woisa+="Therefore, the subject-matter of claim "+cl+" is inventive."+BR2;  	
     break;
   }
 }
 return woisa;
}

MOD_WOI.ok_eq=function(l_clist,opttext) {
  return stdcls_apply_grant("mutatismutandis",l_clist.getValue(),MOD_WOI.law)+BR;
} 

MOD_WOI.ok_indep=function(l_allindepok,lang) {
  var woisa="";
  var allnoteq=l_allindepok.select(function(cl) { return !GetClaimEq(cl);});
  var alleq   =l_allindepok.select(function(cl) { return  GetClaimEq(cl);});
  var cl_iter =allnoteq.iterator();
 
  while(!cl_iter.end()) {
    woisa+=MOD_WOI.ok_claim(cl_iter.getValue(),GetClaimDoc_A(cl_iter.getValue()),lang);     
    cl_iter.next();
  }
  if(alleq.length()>0) {	
    woisa+=MOD_WOI.ok_eq(alleq,"independent");
  }	    
  return woisa;
}

MOD_WOI.ok_dep=function(l_clist) {
  var l_iter=l_clist.iterator();
  var firstok= new List();
  var otherok= new List();
  var woi="";
  while(!l_iter.end()) {
    if(IsClaimNovelandInventive(GetClaimDep(l_iter.getValue()))){
      otherok.push(l_iter.getValue());
    } else {
      firstok.push(l_iter.getValue());
    }
    l_iter.next();
  }

  if(firstok.length()>0) {
    woi+=stdcls_apply_grant("okdep",firstok.getValue(),MOD_WOI.law)+BR;
  } 
  if(otherok.length()>0) {
    woi+=stdcls_apply_grant("okalldep",otherok.getValue(),MOD_WOI.law)+BR; 
  }
  return woi;
}
  


MOD_WOI.indep_txt=function(opt,clist,lang) {
  //var indep=select_nuindep(clist);
  //var numindep=list_count(indep);
  var woisa="";
  
  var cl_iter = new List_iterator(clist);
  
  while(!cl_iter.end()) {
    var firstindep=cl_iter.getValue();    
    var eq = GetClaimEq(firstindep); 
    if(eq && !is_clindependent(eq)) {
      woisa+="***** Independent claim "+firstindep+" is set equal to dependent claim "+eq+ " ***************"+BR2;
    }	
    if(!(eq && is_clindependent(eq))) {     
      var eqindep=select_eq_to(firstindep,clist);
      var numeqindep=list_count(eqindep);                      
      switch(opt) {
      case "new":
	woisa+=comm_lack_novelty(firstindep,GetClaimDoc_X(firstindep),lang);
	if(numeqindep) {
	  woisa+=stdcls_apply_nov("mutatismutandis",eqindep,MOD_WOI.law);
	}
	break;
      case "inv":
	woisa+=comm_lack_inventive(firstindep,GetClaimDoc_X(firstindep),lang,0,"enum");
	if(numeqindep) {
	  woisa+=stdcls_apply_inv("mutatismutandis",eqindep,MOD_WOI.law);
	}
	break;
      }        
    }
    cl_iter.next();
  }
  return woisa+BR2;
}



MOD_WOI.novelty_indep=function(l_allnov,lang) {
    return MOD_WOI.indep_txt("new",l_allnov.getValue(),lang);
}

MOD_WOI.novelty_dep=function(l_allnov) {
  return stdcls_apply_nov("alldependent",l_allnov.getValue(),MOD_WOI.law)+BR;
}


MOD_WOI.inventive_indep=function(l_allinv,lang) {
  //alert("alldependent  in "+ l_allinv.getValue()+" "+MOD_WOI.law);
    return MOD_WOI.indep_txt("inv",l_allinv.getValue(),lang);
}


MOD_WOI.inventive_dep=function(l_allinv,doclist) {
  //alert("allinvdependent  in "+ l_allinv.getValue()+" "+MOD_WOI.law);
  return stdcls_apply_inv("alldependent",l_allinv.getValue(),MOD_WOI.law,doclist)+BR;
}
 
MOD_WOI.industrial=function(clist) {
  return stdcls_apply_misc("industrialyes",clist,MOD_WOI.law)+BR;
}


function pct_clarity(gclaims) {
  var pcth="<H3> Re Item VIII<BR>";
  pcth+="Certain observations on the international application</H3>";
  
  return pcth+comm_area(pct_doclarity(gclaims));
}

MOD_WOI.nucomm=function() {
  var woinu="";
  var woisanuh="";  

  codeprt();

  if(GetGroupsLength() > 1) {
    MOD_NU.nustyle=html_selected("nustyle",MOD_NU.NUSTYLES,MOD_NU.nustyle);
    //var woisanuh ="<h2>Box IV </h2>";
    woisanuh+="<h3>Lack of unity of invention. ";
    woisanuh+=html_selection("nustyle",MOD_NU.NUSTYLES,MOD_NU.nustyle,"MOD_WOI.show_comm()");
    woisanuh+="</h3>";
    if(MOD_NU.nustyle=="Short") {
      woinu+=stdcls_apply_unity("header","",MOD_WOI.law,"")+BR; 
      woinu+=nu_inventions("",MOD_WOI.law);
      woinu+=nu_prior_art(MOD_WOI.law)+BR;
      woinu+=nu_differences(MOD_WOI.law);
      woinu+=nu_problems(MOD_NU.nustyle,MOD_WOI.law);
      woinu+=nu_stf(MOD_WOI.law)+BR;

      woinu+=stdcls_apply_unity("F08","",MOD_WOI.law)+BR;
      woinu+=nu_late_aposteriori(MOD_WOI.law)+BR;      
      woinu+=stdcls_apply_unity("conclusion","",MOD_WOI.law)+BR;
      
    } else {
      woinu+="This Authority found multiple (groups of) inventions ";
      woinu+="in this international application, as follows:"+BR2;
      woinu+=nu_inventions("noheader",MOD_WOI.law)+BR2;
      woinu+=nu_describe_all_stfs();
      woinu+="Therefore, this Authority is of the opinion that ";
      woinu+=GetGroupsLength()+" inventions are claimed :"+BR2;
      woinu+=nu_inventions("noheader")+BR2;
      woinu+=nu_problems(MOD_NU.nustyle,MOD_WOI.law);
      woinu+=nu_exponential();
    }    
    return woisanuh+comm_area(woinu);
  } else {
    return comm_area("Only one invention is declared");
  } 	

}
  


MOD_WOI.subcomm=function(gclaims,gname,lang,law) {
  stdcls_init();
  var woisa="";
  if(gclaims) {
    var allcl =new List();
    var allnov=new List();
    var allinv=new List();
    var allok =new List();
    var allnoop= new List(); // no opinion 
    
    split_claims(gclaims, allcl,allnov,allinv,allok,allnoop);
    
    if(MOD_WOI.pctopt != "408") {
      if(GetGroupsLength() >1 ) {
	nmcl=list_count(gclaims);
	woisa+=BR+"Group "+gname+" ("+plural(nmcl,"Claim")+" "+List_tolist(gclaims)+")"+BR2;
      }
    }
    
    
    if(allok.length()) {       
      //woisa+=MOD_WOI.ok_header(allok.getValue());
      woisa+=MOD_WOI.ok_indep(allok.select(is_clindependent),lang);	
      var dep=allok.select(is_cldependent);
      if(dep.length()) {
	woisa+=MOD_WOI.ok_dep(dep)+BR;
      }
    }
    
    if(allnov.length()) {   
      woisa+=stdcls_apply_nov("header",allnov.getValue(),law)+BR;
      woisa+=MOD_WOI.novelty_indep(allnov.select(is_clindependent),lang);
	var dep=allnov.select(is_cldependent);
	if(dep.length()) {
	  woisa+=MOD_WOI.novelty_dep(dep)+BR;
	}	
      }      

      if(allinv.length()) {
	woisa+=stdcls_apply_inv("header",allinv.getValue(),law)+BR;
	//woisa+=pct_inventive_header(allinv.getValue());
	woisa+=MOD_WOI.inventive_indep(allinv.select(is_clindependent),lang);
	var dep=allinv.select(is_cldependent);
	if(dep.length()) {
	  woisa+=MOD_WOI.inventive_dep(dep)+BR;
	}	
      }
      woisa+=MOD_WOI.industrial(gclaims);

    }
  
  return woisa;
}



MOD_WOI.comm=function(List_in) {
  stdcls_init();
  var woisa="";
  var woisah="";

  var allcl =new List();
  var allnov=new List();
  var allinv=new List();
  var allok =new List();
  var allnoop= new List(); // no opinion 

  split_claims(List_in, allcl,allnov,allinv,allok,allnoop);

  codeprt();  
 
  if(MOD_WOI.pctopt!="408") {
    woisah +="<h3>Statement under Rule 43bis 1(a)(i)</h3>" ;
    woisah +="<TABLE border=1><TR><TD><b>Novelty (N)</b></TD>";
    // if not inventive then new (excepted very exotic situations not worth contemplating)
    // if not new then not inventive (see columbus)
    woisah +="<TD><b>YES:</b></TD><TD  align=right><input type=text readonly size=60 value='"+List_tolist(allok.getValue()+","+allinv.getValue())+"'></TD></TR>";
    woisah +="<TR><TD></TD><TD><b>NO:</b></TD><TD align=right><input type=text size=60 readonly value='"+allnov.compact()+"'></TD></TR>";
    woisah +="<TR><TD><b>Inventive Step (IS)</b></TD><TD><b> YES:</b></TD><TD align=right><input type=text size=60 readonly value='"+allok.compact()+"'></TD></TR>";
    woisah +="<TR><TD></TD><TD><b>NO:</b></TD><TD align=right><input type=text size=60 readonly value='"+List_tolist(allinv.getValue()+","+allnov.getValue())+"'></TD></TR>";
    woisah +="<TR><TD><b>Industrial applicability (IA)</b></TD><TD><b> YES:</b></TD><TD align=right><input type=text size=60 readonly value='"+List_tolist(List_in)+"'></TD></TR>";
    woisah +="<TR><TD></TD><TD><b>NO:</b></TD><TD align=right><input type=text size=60 readonly value=''></TD></TR>";
    woisah +="</TABLE>";
  }

  woisah +="<h2>Item V</h2>";
  woisah +="<h3>Reasoned statement with regard to novelty, inventive step or industrial <BR>";
  woisah +="applicability; citations and explanations supporting such statement </h3>";
  
  woisa+=comm_listciteddocs(List_in,MOD_WOI.law)+BR2;
  
  MOD_WOI.law=GetClaimSetLaw();
  MOD_WOI.lang=GetDossierLang();

  if(GetGroupsLength()>1) { 
    var gr_iter=new group_iterator(); 
    while(!gr_iter.end()) {      
      if(gr_iter.isPaid()) {
	woisa+=MOD_WOI.subcomm(gr_iter.getClaimList(),gr_iter.getName(),MOD_WOI.lang,MOD_WOI.law); 
      }
      gr_iter.next();
    }
  } else {
    woisa+=MOD_WOI.subcomm(List_in,"",MOD_WOI.lang,MOD_WOI.law);
  }

  return woisah+comm_area(woisa);
}


function show_408() {
  return MOD_WOI.show_comm("408");
}

function show_409() {
  return MOD_WOI.show_comm("409");
}

function show_woisa() {
  MOD_WOI.law="PCT";
  return MOD_WOI.show_comm("WOISA");
}

function show_wonat() {
  return MOD_WOI.show_comm("WONAT");
}

MOD_WOI.woitab["Box IV"]={ callback:MOD_WOI.nucomm};
MOD_WOI.woitab["Box V"]={callback: function() { return MOD_WOI.comm(GetFilterClaims());},def:1};
MOD_WOI.woitab["Box VIII"]={callback: function () { return pct_clarity(filteredclaims());}};

MOD_WOI.show_comm=function(opt) {  
  MOD_WOI.woitab["Box IV"].disabled=GetGroupsLength()<=1;
  ClaimToolCommSection(opt,
		       html_tabs_obj("pctview",MOD_WOI.woitab),
		       "MOD_WOI.show_comm()");
}
